<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <button id="btn">download</button>
  <script>
    const btn = document.getElementById('btn')
    btn.addEventListener('click',() => {
      fetch('http://127.0.0.1:3000/download',{
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          filename: '1.JPG'
        })
      }).then(res => res.arrayBuffer()).then(res => {
        // 转成blob
        const blob = new Blob([res],{type: 'image/jpg'})
        // 转url
        const url = URL.createObjectURL(blob)
        // 创建a标签 挂载url 模拟点击
        const a = document.createElement('a')
        a.href = url
        a.download = '1.JPG'
        a.click()
      })
    })
  </script>
</body>
</html>